package ua.org.softworks.dm.utils.jelastic;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created with IntelliJ IDEA.
 * User: dfahritdinov
 * Date: 8/10/12
 * Time: 11:04 AM
 * To change this template use File | Settings | File Templates.
 */
@WebServlet(urlPatterns = "/*")
public class JelacticTestServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        // Параметр
        String parameter = request.getParameter("parameter");
        System.out.println("\n\t\t###\t" + parameter + "\t" + this + "\t" + getServletInfo());

        // Старт HTTP сессии
        if (request.getSession() == null) {
            HttpSession session = request.getSession(true);
            session.setAttribute("parameter", parameter);
        }

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Заголовок</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Пример сервлета " + parameter + " #1.0</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

    @Override
    public String getServletInfo() {
        return "Пример сервлета";
    }

}
